package com.dance.sharevalidator.entity;

import com.dance.sharevalidator.validation.sequenceprovider.EmpGroupSequenceProvider;
import lombok.Data;
import org.hibernate.validator.group.GroupSequenceProvider;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import javax.validation.constraints.Pattern;

@Data
@GroupSequenceProvider(EmpGroupSequenceProvider.class)
public class Emp {

    /**
     * id
     * 希望在添加的时候 @Null生效
     * 希望在更新的时候 @NotNull生效
     * groups 如果是一个可以不写大括号, 多个必须写
     */
    @Null(groups = {Add.class})
    @NotNull(groups = Update.class)
    private Integer id;

    public interface Add{}
    public interface Update{}

    /**
     * 名称
     */
    @NotEmpty
    private String name;

    /**
     * 一个员工属于一个部门(不要强行说多部门容易挨揍)
     */
    @Valid
    private Dept dept;

    @NotNull
    private Integer age;

    @NotEmpty
    @Pattern(regexp = "^初级.*", groups = TitleJunior.class)
    @Pattern(regexp = "^中级.*", groups = TitleMiddle.class)
    private String title;

    // 初级
    public interface TitleJunior{}
    // 中级
    public interface TitleMiddle{}
}
